<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="biz.source_code.miniTemplator.MiniTemplator"%>
<%
            String templateFileName = "login.html";

            String aPath = pageContext.getServletContext().getRealPath(request.getRequestURI()).replace('\\', '/');
            String cPath = request.getContextPath();
            if (cPath.length() > 1) {
                int f1 = aPath.lastIndexOf(cPath);
                aPath = aPath.substring(0, f1) + aPath.substring(f1 + cPath.length());
            }
            aPath = aPath.substring(0, aPath.lastIndexOf('/') + 1);
            session.setAttribute("aPath", aPath);

            MiniTemplator templator = new MiniTemplator(aPath + templateFileName);

            templator.setVariable("title", "Bumblebee Resort Management - Login");

            if (session.getAttribute("User") != null) {
                response.sendRedirect("index.jsp");
            } else {
                if (session.getAttribute("Status") == null) {
                    if ((request.getParameter("username") != null) && (request.getParameter("password") != null)) {
                        session.setAttribute("Action", "login");
                        String url = "/controller";
                        ServletContext context = getServletContext();
                        RequestDispatcher dispatcher = context.getRequestDispatcher(url);
                        dispatcher.include(request, response);
                        if (session.getAttribute("Status").equals("Successful")) {
                                response.sendRedirect("index.jsp");
                        } else {
                            response.sendRedirect("login.jsp");
                        }
                    }
                }
            }
            session.setAttribute("Status", null);
            out.print(templator.generateOutput());

%>